# vim:fileencoding=utf-8:foldmethod=marker:foldmarker={{{,}}}
# zo command for open fold
# zc command for close fold

# {{{ Default oh-my-zsh things + powerlevel10k
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
export EDITOR="/usr/bin/nvim"

# print neofetch when zsh init
#neofetch

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
#ZSH_THEME="robbyrussell"
ZSH_THEME="powerlevel10k/powerlevel10k"
# don't work (why?)
#ZSH_COLORIZE_TOOL=chroma
#ZSH_COLORIZE_CHROMA_FORMATTER=terminal256

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled  # disable automatic updates
# zstyle ':omz:update' mode auto      # update automatically without asking
zstyle ':omz:update' mode reminder  # just remind me to update when it's time

# Uncomment the following line to change how often to auto-update (in days).
zstyle ':omz:update' frequency 14

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"
HIST_STAMPS="dd.mm.yyyy"
HISTSIZE=100000
SAVEHIST=100000
HISTFILE=~/.cache/zsh/history
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
# }}}


# {{{ Added by sekhali
##### added by sekhali

# {{{ plugins list with description
### plugins list
# https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins


## {{{ alias-finder - find alias for command
# usage
#alias-finder pacman -Q
# this finds all aliases begins from 'pacman -Q'
# }}}


## {{{ chucknorris - print random Chuck Norris quote
# requires
# fortune (AUR), cowsay
# usage
#chuck
# print random Norris quote
#chuck_cow
# print quote in cow think
# }}}


## {{{ colored-man-pages - colors man pages
# usage example
#colored git help clone
# }}}


## {{{ colorize - highlite code syntax (based on file extension)
##!!!!!!!!!! may be not working (why?)
# requires syntax highlighter
# Chroma (go) or Pygments (Python)
# }}}


## {{{ command-not-found - provide suggested packages to be installed if a command can't be found
###!!!!!!!!!! not working (why?) 
###!!!!!!!!!! modified (shebang line)
# }}}


## {{{ copybuffer - copy current text in command line to system clipboard
# usage
#ctrl+o
# }}}


## {{{ copyfile - copy full file content to system clipboard
# usage
#copyfile [file/path]
# }}}


## {{{ emoji - for use Unicode emoji in zsh
# usage
# specific emoji
#echo $emoji[<name>]
#echo $emoji[mouse_face]
# random emoji
#random_emoji
# random emoji from particular group
#random_emoji <group>
#random_emoji fruits
# list all available emoji
#display_emoji
#display_emoji <group>
#display_emoji faces
# }}}
 

## {{{ extract - extract archive file, supports wide variety of archive filetypes
# usage
#extract [path/to/archive]
# }}}


## history-substring-search - type any part of command for search it in history by UP and DOWN keys


## {{{ man - shortcut for man (learn how to use hotkey [ESC]+command)
# usage
#[ESC]+man (write like command with pushed [ESC])
# }}}


## zsh-syntax-highlighting - highlight syntax in zsh


## {{{ zsh-autosuggestions
# usage
#[End] - complete full command
#[Ctrl]+[Right arrow] - complete 1 word in command
# }}}


##### {{{ may be useful

#autoenv
#autojump (requires autojump package (AUR)
#battery (for notebooks)
#Bower (web sites manager)
#cake && cakephp3 (php framework plugins)
#compleat (autocomplete for parameters) (built-in?)
#composer (dependency manager for php)
#copypath (copy absolute path to directory (usage - 'copypath [path/to/file/or/directory]'))
#cp (addes cpv command that uses rsync for copying)
#deno (javascript runtime)
#direnv (provides using and changing environment variable only in one directory (not in all the system))
#dnote (CLI note book)
#docker
#docker-compose
#docker-machine
#dotnet (.NET Core CLI plugin)
#eecms (auto-completion for eecms(ExpressionEngine CMS (Open-source)))
#encode64 (encoding text/file and decoding text using base64 command) (modified and realized in .zshrc)
#fabric (Python lib to execute shell commands over SSH and returning useful Python objects)
#fancy-ztrl-z (unsuspend suspended process) (realized in .zshrc)
#fastfile (creating shortcuts to dirs/files (works like variables))
#fbterm (runs fbterm in real TTY) (broken?)
#git-auto-fetch (autofetching all changes from all remotes while u working in a git-initialized dir)
#git-escape-magic (adding escape symbol to meta-characters in git commands)
#git-extras (requires git-extras package) (adding some commands to git, that allow input less count of commands)
#ipfs (completion for IPFS) (P2P hypermedia protocol (InterPlanetary File System))
#nmap (aliases for nmap) (learn aliases)
#systemadmin (aliases for sysadmins)
#thefuck (legendary shit. previous command fixer)
#themes (realtime change themes for zsh)
#zsh-interactive-cd (requires fzf) (interactive cd command)

##### end may be useful
# }}}

# end plugins list with description }}}

### end added by sekhali
# }}}


# {{{ active plugins
plugins=(
	git 
	alias-finder 
	chucknorris 
	colored-man-pages 
	command-not-found 
	copybuffer 
	copyfile 
	emoji 
	extract 
	history-substring-search 
	man 
	zsh-syntax-highlighting 
	zsh-autosuggestions
	)
# }}}


# {{{ continue default oh-my-zsh things
source $ZSH/oh-my-zsh.sh
# source for command-not-found
~/.oh-my-zsh/plugins/command-not-found/command-not-found.plugin.zsh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8
export LANG=ru_RU.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
# }}}


###### {{{ Added by sekhali

##### {{{ misc functions

# check .inputrc

##### end misc functions }}}


##### {{{ aliases


#### {{{ suffix aliases
#### used for open files with prefering editor

alias -s txt=nvim
alias -s cs=nvim
alias -s cpp=nvim
alias -s lua=nvim
alias -s cfg=nvim
alias -s conf=nvim
alias -s zsh=/bin/zsh
alias -s sh=/bin/bash

#### end suffix aliases }}}


#### {{{ global aliases
#### can work in millde or end of command

# syntax is
#alias -g upgdg='sudo pacman -Syu'

# redirection to null
alias -g TN='2>/dev/null'


#### end global aliases }}}


#### {{{ function aliases
###### list of available keycodes
# https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Standard-Widgets
#### using functions as aliases

# {{{ syntax
#[alias-name](){
#	command $parameter1 $parameter2
#}
# }}}
# {{{ example
#find_man() {
#	man $1 | grep -- $2
#}
# }}}
# {{{ usage example
#find_man kill "SIGTERM"
# }}}


### {{{ adding pair to symbol

close-square-bracket() {
	LBUFFER="${LBUFFER}["
	RBUFFER="]${RBUFFER}"
}
zle -N close-square-bracket
bindkey '[' close-square-bracket

close-curly-bracket() {
	LBUFFER="${LBUFFER}{"
	RBUFFER="}${RBUFFER}"
}
zle -N close-curly-bracket
bindkey '{' close-curly-bracket

close-round-bracket() 
{
	LBUFFER="${LBUFFER}("
	RBUFFER=")${RBUFFER}"
}
zle -N close-round-bracket
bindkey '(' close-round-bracket

close-apostrophe() {
	LBUFFER="${LBUFFER}'"
	RBUFFER="'${RBUFFER}"
}
zle -N close-apostrophe
bindkey '\047' close-apostrophe

close-tilda-dot() {
	LBUFFER="${LBUFFER}\`"
	RBUFFER="\`${RBUFFER}"
}
zle -N close-tilda-dot
bindkey '`' close-tilda-dot

close-quotes() {
	LBUFFER="${LBUFFER}\""
	RBUFFER="\"${RBUFFER}"
}
zle -N close-quotes
bindkey '"' close-quotes

### end adding pair to symbol }}}


### {{{ misc


## {{{ work with base64

encode64() {
	if [[ $# -eq 0 ]]; then
		#echo "No text to encode"
		cat | base64
	else
		echo $1 | base64
	fi
}

encode-file64() {
	if [[ $# -eq 0 ]]; then
		echo "You must write path to file for encode"
	else
		base64 $1 > $1.txt
		echo "${1}'s content encoded in base64 and saved as ${1}.txt"
	fi
}

decode64() {
	if [[ $# -eq 0 ]]; then
		#echo "No text to decode"
		cat | base64 --decode
	else
		printf '%s' $1 | base64 --decode
	fi
}

decode-file64() {
	if [[ $# -eq 0 ]]; then
		echo "You must write path to file for encode"
	else
		base64 --decode $1 > $1.txt
		echo "${1}'s content decoded from base64 and saved as ${1}.txt"
	fi
}

## end work with base64 }}}


## {{{ system things


# {{{ fancy-ctrl-z realization
fancy-ctrl-z () {
	if [[ $#BUFFER -eq 0 ]]; then
		BUFFER="fg"
		zle accept-line -w
	fi
}
# }}}


# {{{ find--everywhere
find--everywhere () {
	if [[ $# -eq 0 ]]; then
		echo "No word to find"
	else
		find / -name $1 2>/dev/null
	fi
}
# }}}


# {{{ open-ranger (by Ctrl+g hotkey)
open-ranger() {
	# if there is no command typed, open ranger in current directory
	if [[ $#BUFFER -eq 0 ]]; then
		BUFFER="ranger `pwd`"
		zle accept-line -w
	# if there is command typed, comment and push it, then open ranger in current directory
	else
		BUFFER="# $BUFFER"
		zle accept-line -w
		#BUFFER="#ranger `pwd`"
		#zle accept-line -w
	fi
    # if there is no command typed, use the last command
    #[[ -z "$BUFFER" ]] && zle up-history

    # if typed command begins with man, do nothing
    #[[ "$BUFFER" = man\ * ]] && return

    # get command and possible subcommand
    # http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags
    #local -a args
    #args=(${${(Az)BUFFER}[1]} ${${(Az)BUFFER}[2]})

    # check if man page exists for command and first argument
    #if man "${args[1]}-${args[2]}" >/dev/null 2>&1; then
    #    BUFFER="man $args"
    #else
    #    BUFFER="man ${args[1]}"
    #fi
}
zle -N open-ranger
# Defined shortcut keys: [Ctrl]g
bindkey "\C"g open-ranger
# }}}


## end system things }}}


## {{{ jokes

# {{{ gachi string
#requires emoji plugin
gachi() {
	if [[ $# -eq 0 ]]; then
		echo $emoji[male_sign]$emoji[male_sign]
	else
		echo $emoji[male_sign]$1$emoji[male_sign]
	fi
}
# }}}

## end jokes }}}


### end misc }}}


#### end function aliases }}}


#### {{{ normal aliases

### {{{ Rewrite shell-built aliases

alias l='ls -lFh'
alias la='ls -lFha'
alias l--dot='ls -ld .*'
alias l--col='ls -1F'
alias la--col='ls -1aF'

### end rewrite shell-built aliases }}}


### {{{ pacman and paru

alias inst='sudo pacman -Sy --needed'
alias pacman--upg='sudo pacman -Syu'
alias pacman--rem='sudo pacman -Rscun'
alias pacman--reposearch='pacman -Ss'
alias pacman--localsearch='pacman -Qs | grep'
alias pacman--package-owner='pacman -Qo'
# clean old and unused cache and packages
alias paclean='sudo pacman -Sc'
# erase all pacman cache
alias pacman--erasecache='sudo pacman -Scc'
alias pacman--orphans-show='pacman -Qdt'
# erase all orphan packages
alias pacman--oprhans-erase='sudo pacman -Rs $(pacman -Qtdq)'


alias paru--upg='paru --aur -Syu'
alias paru--aur='paru --aur'
alias paru--rem='paru -Rscun'

alias upgdg='sudo pacman -Syu && paru --aur -Syu && sudo mkinitcpio -p linux-zen && sudo pacman -Sc'

### end pacman and paru }}}


### {{{ system things

alias cls='clear'
alias lsblk_sys='lsblk -o name,parttypename,label,partlabel,pttype,model,mode,fstype,fsver,size,fsavail,fsused,fsuse%,mountpoints'
alias lsblko='lsblk -o name,label,fstype,fsver,uuid,size,fsavail,fsused,fsuse%,mountpoints'
alias zshrc='nvim ~/.zshrc'
alias awesome--config='nvim ~/.config/awesome/rc.lua'
alias awesome--test='Xephyr :5 & sleep 1 ; DISPLAY=:5 awesome'
# show files with size
alias pwd--files-size='du -d 1 -h'
alias pwd--size='du -sh'
alias hist--grep='fc -El 0 | grep'
alias cur--processes='ps -f' 
alias ..='cd ..'
alias ....='cd ../..'
alias ......='cd ../../..'
alias ........='cd ../../../..'

alias _autostart_script='sudo ~/autostart_scripts/main.sh'

alias cleanup='sudo pacman -Scc && sudo pacman -Qtdq && echo "\nOrphans shown. Type \"sudo pacman -Qtdq | sudo pacman -Rns -\" for delete them" && echo "Or for show optional depends type \"pacman -Qttdq\"" && echo "For see info about package type \"pacman -Qii [package-name]\" and watch at \"Required By\" line" && echo "Type \"pacman -Qe\" for see manually installed packages" && echo "Type \"pacman -Qm\" for see third-party packages (mainly from AUR)\n"'

### end system things }}}


### {{{ no category

alias exa--long='exa -alFh --icons'
alias exa--col='exa -a1Fh --icons'
alias exa--recursive='exa -aFTh --icons'
alias exa--longrecursive'exa -alFTh --icons'


### end no category }}}


### {{{ misc

# Launch Minecraft
#alias MINE="/usr/lib/jvm/java-8-openjdk/jre/bin/java -Xmx4096M -Xms4096M -jar ~/minecraft/TLauncher.jar"
alias show='egrep -v "(^#|^$)"'

### end misc }}}


### {{{ Python 

alias pip3in='pip3 install --user --break-system-packages --upgrade'

### End python}}}


### {{{ idk how to use it

# telling that this useful for searching within files
#sgrep='grep -R -n -H -C 5 --exclude-dir={.git,.svn,CVS}'

### end idk how to use it }}}


#### end normal aliases }}}


##### end aliases }}}


###### end added by sekhali }}}


# {{{ Last zsh init things
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# }}}
